package com.amkai.aes.aesws;

import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.handler.MessageContext;

import com.amkai.aes.aescommon.Version;

@WebService()
public class AesMobileWebservice {
	@Resource private WebServiceContext wsContext;

	/**
	 * Web service operation
	 */
	@WebMethod(operationName = "getVersion")
	public String getVersion() {
		return Version.AO_CODE_VERSION_MAJOR_MINOR_RELEASE_BUILD;
	}

	/**
	 * Web service operation
	 */
	@WebMethod()
	public String processMobileJob(@WebParam(name = "mobileJob") String mobileJob) throws Throwable {
		 MessageContext mc = wsContext.getMessageContext();
         HttpSession session = ((HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession();
         // Get a session property "counter" from context
         if (session == null)
             throw new WebServiceException("No session in WebServiceContext");
         
         return MobileJobExecutor.executeJob(session, mobileJob);
		
	}
	
	

}
